package com.goodving.guli.bt.ui;

import android.app.Activity;
import android.app.Fragment;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.goodving.guli.R;
import com.goodving.guli.bt.C0668a;
import com.goodving.guli.bt.DimPanelFragment;
import com.goodving.guli.bt.profile.scale.GuliLog;
import com.goodving.guli.bt.utils.WeightUtil;
import com.goodving.guli.bt.weight.C1974I;
import com.goodving.guli.model.Keeper;
import com.goodving.guli.utility.gulihardware.Constant;
import com.goodving.guli.view.BitmapDescriptorFactory;
import com.goodving.guli.view.C3657a;
import com.goodving.guli.view.C4220a;

import kankan.wheel.widget.OnWheelScrollListener;
import kankan.wheel.widget.WheelView;

/**
 * Created by john on 2015/12/9.
 */
public class C1972G extends DimPanelFragment {
    private static final String f11105c;
    private static float f11106g;
    private WheelView f11107a;
    private WheelView f11108b;
    private int f11109d;
    private int f11110e;
    private int f11111f;
    private C1974I f11112h;
    private PickAdapter f11113i;


    static {
        f11105c = C1972G.class.getSimpleName();
        f11106g = BitmapDescriptorFactory.HUE_YELLOW;
    }

    public C1972G() {
        this.f11109d = 3;
        this.f11110e = Constant.at;
    }

    public static Fragment m15555a(float f) {
        Fragment c1972g = new C1972G();
        f11106g = f;
        return c1972g;
    }

    private int m15557b() {
        return WeightUtil.m15718c(getActivity()) > Constant.at ? 9 : 0;
    }

    public void m15560a(C1974I c1974i) {
        this.f11112h = c1974i;
    }

    protected int inflateLayout() {
        return R.layout.fragment_person_info_setting_weight;
    }

    public void onAttach(Activity activity) {
        super.onAttach(activity);
        try {
            this.f11112h = (C1974I) activity;
        } catch (Exception e) {
        }
    }

    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
    }

    class C1973H implements OnWheelScrollListener {
        final /* synthetic */ C1972G f11114a;

        C1973H(C1972G c1972g) {
            this.f11114a = c1972g;
        }

        public void onScrollingStarted(WheelView wheelView) {
        }

        public void onScrollingFinished(WheelView wheelView) {
            GuliLog.tracePrintInfo(C1972G.f11105c, "item " + wheelView.getRealCurrentItem());
            if (wheelView.getRealCurrentItem() == 631) {
                GuliLog.tracePrintInfo(C1972G.f11105c, " should refresh month");
                PickAdapter dmVar = new PickAdapter(this.f11114a.getActivity(), 0, this.f11114a.m15557b(), this.f11114a.f11108b, this.f11114a.getResources().getColor(R.color.highlight), this.f11114a.getResources().getColor(R.color.main_ui_content_color), C4220a.bm, false, 46, 24, 21, 21, 1);
                dmVar.m14686a(19);

                //this.f11114a.f11108b.m26809e(R.drawable.wheel_custom_val_white_1).m26785a(WeightUtil.m15698a(this.f11114a.getActivity().getApplicationContext(), Keeper.readPersonInfo().miliConfig.weightUnit), 25.123f).m26788a(dmVar).m26804c(0);
                this.f11114a.f11108b.setCenterDrawable(R.drawable.wheel_custom_val_white_1).setCenterStyle(WeightUtil.m15698a(this.f11114a.getActivity().getApplicationContext(), Keeper.readPersonInfo().miliConfig.weightUnit), 25.123f).setViewAdapter(dmVar).setCurrentItem(0);

                return;
            }
            this.f11114a.f11108b.setViewAdapter(this.f11114a.f11113i);
        }
    }

    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        View onCreateView = super.onCreateView(layoutInflater, viewGroup, bundle);
        this.f11111f = Keeper.readPersonInfo().miliConfig.weightUnit;
        this.f11109d = (int) WeightUtil.m15706b(3.0f, this.f11111f);
        this.f11110e = (int) WeightUtil.m15706b((float) WeightUtil.m15718c(getActivity()), this.f11111f);
        this.f11107a = (WheelView) onCreateView.findViewById(R.id.info_weight_int_wheel);
        this.f11108b = (WheelView) onCreateView.findViewById(R.id.info_weight_decimal_wheel);
        WheelView a = this.f11107a.setCenterDrawable(R.drawable.wheel_custom_val_white_1).setCenterStyle(C3657a.f18328f, 25.123f); // m26785a
        a.setViewAdapter(new PickAdapter(getActivity(), this.f11109d, this.f11110e, this.f11107a, getResources().getColor(R.color.highlight), getResources().getColor(R.color.main_ui_content_color), C4220a.bm, false, 46, 24, 21, 21, 1)).setCurrentItem(((int) WeightUtil.m15706b(f11106g, Keeper.readPersonInfo().miliConfig.weightUnit)) - ((int) WeightUtil.m15706b(3.0f, Keeper.readPersonInfo().miliConfig.weightUnit)));
        this.f11113i = new PickAdapter(getActivity(), 0, 9, this.f11107a, getResources().getColor(R.color.highlight), getResources().getColor(R.color.main_ui_content_color), C4220a.bm, false, 46, 24, 21, 21, 1);
        this.f11113i.m14686a(19);
        if (WeightUtil.m15706b(f11106g, Keeper.readPersonInfo().miliConfig.weightUnit) < ((float) this.f11110e)) {
            GuliLog.tracePrintInfo(f11105c, " < max");
            GuliLog.tracePrintInfo(f11105c, " max weight: " + this.f11110e);
            this.f11108b.setCenterDrawable(R.drawable.wheel_custom_val_white_1).setCenterStyle(WeightUtil.m15698a(getActivity().getApplicationContext(), Keeper.readPersonInfo().miliConfig.weightUnit), 25.123f).setViewAdapter(this.f11113i).setCurrentItem(((int) (WeightUtil.m15716c(WeightUtil.m15706b(f11106g, Keeper.readPersonInfo().miliConfig.weightUnit), 1) * 10.0f)) - (((int) WeightUtil.m15706b(f11106g, Keeper.readPersonInfo().miliConfig.weightUnit)) * 10));
            GuliLog.tracePrintInfo(f11105c, "raw " + f11106g);
            GuliLog.tracePrintInfo(f11105c, "to unit" + WeightUtil.m15706b(f11106g, Keeper.readPersonInfo().miliConfig.weightUnit));
            GuliLog.tracePrintInfo(f11105c, "raw*10 -> int " + ((int) (WeightUtil.m15706b(f11106g, Keeper.readPersonInfo().miliConfig.weightUnit) * 10.0f)));
            GuliLog.tracePrintInfo(f11105c, "raw -> int * 10" + (((int) WeightUtil.m15706b(f11106g, Keeper.readPersonInfo().miliConfig.weightUnit)) * 10));
        } else {
            GuliLog.tracePrintInfo(f11105c, " >= max");
            PickAdapter dmVar = new PickAdapter(getActivity(), 0, m15557b(), this.f11108b, getResources().getColor(R.color.highlight), getResources().getColor(R.color.main_ui_content_color), C4220a.bm, false, 46, 24, 21, 21, 1);
            dmVar.m14686a(19);
            this.f11108b.setCenterDrawable(R.drawable.wheel_custom_val_white_1).setCenterStyle(WeightUtil.m15698a(getActivity().getApplicationContext(), Keeper.readPersonInfo().miliConfig.weightUnit), 25.123f).setViewAdapter(dmVar).setCurrentItem(((int) (WeightUtil.m15706b(f11106g, Keeper.readPersonInfo().miliConfig.weightUnit) * 10.0f)) - (((int) WeightUtil.m15706b(f11106g, Keeper.readPersonInfo().miliConfig.weightUnit)) * 10));
        }
        this.f11107a.addScrollingListener(new C1973H(this)); // m26794a
        return onCreateView;
    }

    public void onDestroy() {
        super.onDestroy();
        C0668a.m8128a(getActivity(), C0668a.dY, C3657a.f18328f + f11106g);
    }

    public void onDismiss(DialogInterface dialogInterface) {
        super.onDismiss(dialogInterface);
        if (this.f11112h != null) {
            this.f11112h.m15563a();
        }
    }

    protected void onLeftButtonClicked() {
        super.onLeftButtonClicked();
        if (this.f11112h != null) {
            this.f11112h.m15563a();
        }
    }

    public void onPause() {
        super.onPause();
        C0668a.m8141b(C0668a.f3568k);
    }

    public void onResume() {
        super.onResume();
        C0668a.m8133a(C0668a.f3568k);
    }

    protected void onRightButtonClicked() {
        this.mRightButton.setEnabled(false);
        float a = WeightUtil.m15689a((((float) this.f11107a.getRealCurrentItem()) + (((float) this.f11108b.getRealCurrentItem()) / 10.0f)) + ((float) ((int) WeightUtil.m15706b(3.0f, Keeper.readPersonInfo().miliConfig.weightUnit))), Keeper.readPersonInfo().miliConfig.weightUnit);
        if (this.f11112h != null) {
            this.f11112h.m15564a(a);
        }
        dismiss();
    }
}
